import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    username: "",
    token: "",
    isCollapse: false
  },
  mutations: {
    setUsername: (state, username) => {
      state.username = username;
      localStorage.setItem("username", username);
    },

    setToken: (state, token) => {
      state.token = token;
      localStorage.setItem("token", token);
    },
    changeCollapse: (state)=>{
      state.isCollapse = !state.isCollapse
    }
  },
  actions: {},
  getters: {
    getUserName(state) {
      if(state.username) {
          return  state.username
      }
      return  window.localStorage.getItem('username')
      
  }
  }
});

export default store;
